package com.honglu.backend.controller.app;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
 
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

 
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import com.honglu.backend.common.controller.BaseController;
import com.honglu.backend.entity.Banner;
import com.honglu.backend.service.impl.BannerServiceImpl;
import com.honglu.backend.utils.CodeUtils;
import com.honglu.backend.utils.DateUtils;
import com.honglu.backend.utils.JSONUtils;
 
@Controller
@RequestMapping("/backend/api/banner/")
public class BannerInterfaceController extends BaseController {
	private static Logger logger = Logger.getLogger(BannerInterfaceController.class);
	@Autowired
	private BannerServiceImpl bannerService;


	/**
	 *baner接口
	 * 
	 * @param request
	 * @param response
	 */

	@RequestMapping(value = "interfaceBanner.do", method = RequestMethod.POST)
	public void interfaceBanner(HttpServletRequest request, HttpServletResponse response) {
		List<Map<String, Object>> list1 = new ArrayList<Map<String, Object>>();
		List<Banner> list = bannerService.findBanner(DateUtils.parseToDateTimeStr(new Date()));
		if (list == null || ("").equals(list) || list.size() < 0) {
			JSONUtils.toJSON(response, CodeUtils.QUERY_NULL);
			return;
		} else if(list !=null || !("").equals(list) || list.size() > 0){
			for (int i = 0; i < list.size(); i++) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("title", list.get(i).getTitle());
				map.put("image", list.get(i).getImage());
				map.put("url", list.get(i).getUrl());
				map.put("appVersion", list.get(i).getAppVersion());
				map.put("excuteTime", list.get(i).getExcuteTime());
				map.put("userGroup", list.get(i).getUserGroup());
				map.put("alertPage", list.get(i).getAlertPage());
				map.put("appKey", list.get(i).getAppKey());
				map.put("platform", list.get(i).getPlatform());
				list1.add(map);
			}
			JSONUtils.toJSON(response, CodeUtils.QUERY_SUCCESS, list1);
			return;
		}
	  	 
	}

}
